package com.clubupc.negocio;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

import com.clubupc.dao.BaseDAO;
import com.clubupc.exception.DAOException;
import com.clubupc.modelo.BaseBean;
import com.clubupc.modelo.ProxyBeans;


public class MaterialNegocio {

	public MaterialNegocio() {
	}
	
	public BaseBean getMaterialByNom(String nombre) {
		BaseDAO bd = new BaseDAO();
		BaseBean material = null;
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("nombre", nombre);
		
		try {
			LinkedList<BaseBean> lista = bd.selectByParams(params, "Material");
			if (lista != null && !lista.isEmpty()) {
				material = lista.get(0);
			}
		} catch (DAOException e) {
			e.printStackTrace();
		}
		return material;
	}
	
	public BaseBean createMaterial(String nombre, String descripcion) {

		BaseBean beanMaterial = ProxyBeans.getBaseBean("Material").newInstance();
		beanMaterial.put("nombre", nombre);
		beanMaterial.put("descripcion", descripcion);

		BaseDAO bd = new BaseDAO();
		try {
			beanMaterial = bd.insertByBaseBean(beanMaterial);
			BaseDAO.getMasterTables().put("Material", bd.selectByParams(null, "Material"));
		} catch (DAOException e) {
			e.printStackTrace();
		}
		return beanMaterial;
	}

}
